package com.tchintech.pay.view.activity;

import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.tchintech.pay.R;
import com.tchintech.pay.adapter.FullyGridLayoutManager;
import com.tchintech.pay.adapter.RecycleAdapter;
import com.tchintech.pay.delegate.BankListDelegate;
import com.tchintech.pay.frame.presenter.ActivityPresenter;
import com.tchintech.pay.model.entity.BankList;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/10 0010.
 */

public class BankListActivity extends ActivityPresenter<BankListDelegate> implements View.OnClickListener {

    private RecyclerView recyclerView;
    private RecycleAdapter adapter;
    private Intent intent;

    private BankList backlist;
    private List<BankList> list;
    private String[] bankName = {"浦发银行", "工商银行", "兴业银行", "中信银行", "民生银行", "平安银行", "交通银行", "招商银行", "华夏银行"};
    private String[] baneivName = {"bank01", "bank02", "bank03", "bank04", "bank05", "bank06", "bank07", "bank08", "bank09"};
    private String[] lodurl = {"https://ecentre.spdbccc.com.cn/creditcard/indexActivity.htm?data=P1521124"
            , "https://mims.icbc.com.cn/IMServiceServer/servlet/ICBCBaseReqNSServlet?dse_operationName=ApplyCreditCardOp&coreCode=HZDW000010961&paraPromoCode=EW0001402000000KL02"
            , "https://ccshop.cib.com.cn:8010/application/cardapp/cappl/ApplyCard/toSelectCard?id=bea6615a09544d87b227711f0441f674"
            , "http://creditcard.ecitic.com/h5/shenqing/shanghu/index.html?sid=SJUQZRFB2"
            , "https://creditcard.cmbc.com.cn/wsonline/home/homeHZ.jhtml?recommendInfo=LCzb5Wm4XEDWOifNjlX0UV7UEw6XkQwuugAGGbWFGhFi0UAxmEVMEb5OH36nsG82M2KurRhra3UOgfqIdjf+JcpzeI3SSZIlR2fLQoDkCekTW+Sa79yr4/AJlUY7PUReC3f6naeWlgGTw1h2dmxQTfq2sSg0b31fPclBOCg0NamXVeAYH3DOwutA2I0ckmfkh25DdV/LqLWpbi13NWWJuil+ZwwbEsSlfywSHxNaiWs16hZkJfvlKcpK7aatrf/SUXyTrgCmTsub9A8mwOLroBDXg2pmE68QamsV+jfptZiOO2KGisxkJF4N6cQlPcg0E23ZbT0dN+Qu7P9dUzY/CQ==&time=1499654491300&time=1499654496344"};

    @Override
    protected void initView() {
        super.initView();
        setData();
        viewDelegate.setVisible();
        viewDelegate.setTitles("信用卡申请");
        viewDelegate.setOnClickListener(this, R.id.iv_back);
        recyclerView = viewDelegate.getRecycle();
       // recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        //解决滑动冲突
        recyclerView.setLayoutManager(new FullyGridLayoutManager(this, 3));
        adapter = new RecycleAdapter(this, list);
        recyclerView.setAdapter(adapter);
        //recyclerView.addItemDecoration(new DividerGridItemDecoration(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        Listener();
    }

    @Override
    protected void initData() {
        super.initData();
        list = new ArrayList<BankList>();
        intent = new Intent();
        System.out.println("设置标题");

    }


    private void Listener() {
        adapter.setOnItemClickLitener(new RecycleAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(View view, String name) {
                showWeb(name);

            }
        });
    }

    private void showWeb(String name) {
        switch (name) {
            case "bank01":
                intent.setClass(this, BankWebview.class);
                intent.putExtra("url", lodurl[0]);
                startActivity(intent);
                break;
            case "bank02":
                intent.setClass(this, BankWebview.class);
                intent.putExtra("url", lodurl[1]);
                startActivity(intent);
                break;
            case "bank03":
                intent.setClass(this, BankWebview.class);
                intent.putExtra("url", lodurl[2]);
                startActivity(intent);
                break;
            case "bank04":
                intent.setClass(this, BankWebview.class);
                intent.putExtra("url", lodurl[3]);
                startActivity(intent);
                break;
            case "bank05":
                intent.setClass(this, BankWebview.class);
                intent.putExtra("url", lodurl[4]);
                startActivity(intent);
                break;
            default:
                showMsg("即将开通，敬请期待...");
                break;
        }
    }


    private void setData() {
        for (int i = 0; i < 9; i++) {
            BankList backlist = new BankList();
            backlist.setBankName(bankName[i]);
            backlist.setBankivname(baneivName[i]);
            list.add(backlist);
        }
    }


    @Override
    protected Class<BankListDelegate> getDelegateClass() {
        return BankListDelegate.class;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
